

#import "FAMCameAdjustmentTableViewCell.h"
@interface FAMCameAdjustmentTableViewCell()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *FAMFoodNameTextField;
@property (weak, nonatomic) IBOutlet UITextField *FAMWeightTextField;

@end
@implementation FAMCameAdjustmentTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(FAM_keyboardWillHide) name:UIKeyboardWillHideNotification object:nil];
    self.FAMFoodNameTextField.delegate = self;
    self.FAMWeightTextField.delegate = self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}
- (IBAction)FAM_deleteButtonClick:(UIButton *)sender {
    if (self.block) {
        self.block(_FAMFoodModel);
    }
}
- (void)setFAMFoodModel:(FAMFoodIdentifyModel *)FAMFoodModel{
    _FAMFoodModel = FAMFoodModel;
    self.FAMFoodNameTextField.text = [NSString nullToString:FAMFoodModel.food_name];
    self.FAMWeightTextField.text = FAMFoodModel.weight;
}
- (void)FAM_keyboardWillHide{
    if (self.FAMFoodNameTextField.isFirstResponder) {
        _FAMFoodModel.food_name = self.FAMFoodNameTextField.text;
    }
    if (self.FAMWeightTextField.isFirstResponder) {
        _FAMFoodModel.weight = self.FAMWeightTextField.text;
    }
}
- (void)dealloc {
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
    if (textField == self.FAMFoodNameTextField) {
        _FAMFoodModel.food_name = self.FAMFoodNameTextField.text;
    }else{
        _FAMFoodModel.weight = self.FAMWeightTextField.text;
    }
}
@end
